home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / zendisk2.zip / LST11-3.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  1KB  |  61 lines

  1. ;
  2. ; *** Listing 11-3 ***
  3. ;
  4. ; Converts all characters in a string to uppercase,
  5. ; using a loop containing LODSB and STOSB and using
  6. ; two pointers.
  7. ;
  8.     jmp    Skip
  9. ;
  10. SourceString    label    word
  11.     db    'This space intentionally left not blank',0
  12. ;
  13. ; Copies one zero-terminated string to another string,
  14. ; converting all characters to uppercase.
  15. ;
  16. ; Input:
  17. ;    DS:SI = start of source string
  18. ;    ES:DI = start of destination string
  19. ;
  20. ; Output:
  21. ;    none
  22. ;
  23. ; Registers altered: AL, BX, SI, DI
  24. ;
  25. ; Direction flag cleared
  26. ;
  27. ; Note: Does not handle strings that are longer than 64K
  28. ;    bytes or cross segment boundaries.
  29. ;
  30. CopyStringUpper:
  31.     mov    bl,'a'    ;set up for fast register-register
  32.     mov    bh,'z'    ; comparisons
  33.     cld
  34. StringUpperLoop:
  35.     lodsb        ;get the next character and
  36.             ; point to the following character
  37.     cmp    al,bl    ;below 'a'?
  38.     jb    IsUpper    ;yes, not lowercase
  39.     cmp    al,bh    ;above 'z'?
  40.     ja    IsUpper    ;yes, not lowercase
  41.     and    al,not 20h ;is lowercase-make uppercase
  42. IsUpper:
  43.     stosb        ;put the uppercase character into
  44.             ; the new string and point to the
  45.             ; following character
  46.     and    al,al    ;is this the zero that marks the
  47.             ; end of the string?
  48.     jnz    StringUpperLoop ;no, do the next character
  49.     ret
  50. ;
  51. Skip:
  52.     call    ZTimerOn
  53.     mov    si,offset SourceString    ;point DS:SI to the
  54.                     ; string to convert
  55.     mov    di,ds
  56.     mov    es,di            ;point ES:DI to the
  57.     mov    di,si            ; same string
  58.     call    CopyStringUpper        ;convert to
  59.                     ; uppercase in place
  60.     call    ZTimerOff
  61.